package com.richie696.connect;

import com.richie696.catalina.Engine;
import com.richie696.catalina.connector.Connector;

import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;

public class Service {

    private String name;

    private final Map<String, CatalinaExecutor> executorMap = new ConcurrentHashMap<>(5);

    private final Map<Integer, Connector> connectorMap = new ConcurrentHashMap<>(5);

    private Engine engine;

    private final Map<Integer, ServerSocket> socketMap = new ConcurrentHashMap<>(5);

    private final AtomicBoolean start = new AtomicBoolean(true);


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Engine getEngine() {
        return engine;
    }

    public void setEngine(Engine engine) {
        this.engine = engine;
    }

    public void addExecutor(String name, CatalinaExecutor executor) {
        executorMap.put(name, executor);
    }

    public CatalinaExecutor getExecutor(String name) {
        return executorMap.get(name);
    }

    public void addConnector(Integer port, Connector connector) {
        connectorMap.put(port, connector);
    }

    public Connector getConnector(Integer port) {
        return connectorMap.get(port);
    }

    public List<Connector> getConnectors() {
        return new ArrayList<>(connectorMap.values());
    }

    public void addServerSocket(int port, ServerSocket serverSocket) {
        socketMap.put(port, serverSocket);
    }

    public ServerSocket getServerSocket(int port) {
        return socketMap.get(port);
    }

    public boolean isStart() {
        return start.get();
    }

    public void setStart(boolean start) {
        this.start.set(start);
    }

}
